<?php
	class Messages extends BaseArq {
		
		private static $bundleMessageKey = "MESSAGE_BUNDLE_IN_MEMORY";
		private static $bundleConfigKey = "CONFIG_BUNDLE_IN_MEMORY";
		private static $i18nDir = "include/i18n/";
		private static $i18nFilePrefix = "messages_";
		private static $i18nFileSufix = ".txt";
		
		public static function getMessageString($key) {
			$bundle = Scope::loadSessionVar(self::$bundleMessageKey);
			if( $bundle == null ) {
				self::openBundle();
				$bundle = Scope::loadSessionVar(self::$bundleMessageKey);
			}
			if( $key != null || $key != "" ) {
				return $bundle[$key];	
			} else {
				return $key;
			}
		}
		
		public static function getConfigString($key) {
			$bundle = Scope::loadSessionVar(self::$bundleConfigKey);
			if( $bundle == null ) {
				self::openBundle();
				$bundle = Scope::loadSessionVar(self::$bundleConfigKey);
			}
			if( $key != null || $key != "" ) {
				return $bundle[$key];	
			} else {
				return $key;
			}
		}
		
		private static function openBundle() {
			$lang = Scope::getLocale();
			$message = Scope::loadSessionVar(self::$bundleMessageKey);
			if( $message == null ) {
				$message = FileUtils::loadPropertyInArray(self::$i18nDir . self::$i18nFilePrefix . $lang . self::$i18nFileSufix);
				Scope::putSessionVar(self::$bundleMessageKey, $message);
			}
			$config = Scope::loadSessionVar(self::$bundleConfigKey);
			if( $config == null ) {
				$config = FileUtils::loadPropertyInArray("include/config/config.properties");
				Scope::putSessionVar(self::$bundleConfigKey, $config);
			}			
		}
	}
?>